package hz.mobileproject.pda.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.blankj.utilcode.util.TimeUtils;

import java.util.ArrayList;
import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.entity.response.Response_CallRecord;
import hz.mobileproject.pda.entity.response.Response_CallRecord;

/**
 * Created by Lc on 2017/10/25.
 */

public class CallRecordAdapter extends BaseAdapter {
    private Context mContext;
    private List<Response_CallRecord> listData;
    private LayoutInflater inflater;

    public CallRecordAdapter(Context mContext, List<Response_CallRecord> listData) {
        this.mContext = mContext;
        this.listData = listData;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return listData.size();
    }

    @Override
    public Object getItem(int position) {
        return listData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.item_call_record,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Response_CallRecord callRecord = listData.get(position);
        viewHolder.police_name.setText(callRecord.getPolice_name());
        viewHolder.police_code.setText(callRecord.getPolice_code());
        viewHolder.call_total_num.setText(callRecord.getCall_total_num());
        viewHolder.end_modes_name.setText(callRecord.getEnd_modes_name());
        viewHolder.batch_code.setText(callRecord.getBatch_code());
        viewHolder.start_time.setText(TimeUtils.millis2String(callRecord.getStart_time()));
        viewHolder.end_time.setText(TimeUtils.millis2String(callRecord.getEnd_time()));
        return convertView;
    }

    public void setListData(ArrayList<Response_CallRecord> listData){
        if(listData == null){
            listData = new ArrayList<Response_CallRecord>();
        }
        this.listData = listData;
        notifyDataSetChanged();
    }

    public List<Response_CallRecord> getListData() {
        return listData;
    }

    private class ViewHolder{
        private TextView police_name;
        private TextView police_code;
        private TextView call_total_num;
        private TextView end_modes_name;
        private TextView batch_code;
        private TextView start_time;
        private TextView end_time;

        public ViewHolder(View v) {
            police_name = (TextView)v.findViewById(R.id.police_name);
            police_code = (TextView)v.findViewById(R.id.police_code);
            call_total_num = (TextView)v.findViewById(R.id.call_total_num);
            end_modes_name = (TextView)v.findViewById(R.id.end_modes_name);
            batch_code = (TextView)v.findViewById(R.id.batch_code);
            start_time = (TextView)v.findViewById(R.id.start_time);
            end_time = (TextView)v.findViewById(R.id.end_time);
        }
    }
}
